// 此文件是由模板文件 ".dtpl/page/$rawModuleName.ts.dtpl" 生成的，你可以自行修改模板

import { pagify, MyPage } from 'base/'

const PAGE_SIZE = 30

@pagify()
export default class extends MyPage {
  data = {
    tabs: [
      { title: '全部', id: 1 },
      { title: '待付款', id: 2 },
      { title: '待配送', id: 3 },
      { title: '配送中', id: 4 },
    ],
    selectedId: 1,
    list: [],
    loadmoreFinished: true,
    noMore: false,
    pagination: 1
  }

  async onLoad(options: any) {
    this.getOrders()
  }

  refresh() {
    this.setDataSmart({
      list: [],
      loadmoreFinished: true,
      noMore: false,
      pagination: 1
    })
    this.getOrders()
  }

  async getOrders() {
    this.setDataSmart({ loadmoreFinished: false })
    const { data } = await this.app.fetch({ api: 'orders', params: { pageSize: PAGE_SIZE, pagination: this.data.pagination } })
    this.setDataSmart({
      list: this.data.list.concat(data),
      loadmoreFinished: true,
      noMore: data.length < PAGE_SIZE,
      pagination: this.data.pagination + 1
    })
  }
}
